package com.jindi.appuser.controller.util;

import com.jindi.appuser.common.Const;
import com.jindi.appuser.common.HttpRequest;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: duanj
 * Date: 2018-05-11
 * Time: 10:16
 * Description:
 */
public class GetSmSCodeUtil {
    public static String getCode(String phone,String code){
        String content = "【有意思铃声】您的验证码是" + code + ",在五分钟之内有效。如非本人操作请忽略本短信。";
        String result = SmsClientSend.sendSms(
                Const.SMSCODE_URL, Const.SMSCODE_UID, Const.SMSCODE_UNAME,
                Const.SMSCODE_UPASSWORD,phone,content,"send","POST","UTF-8","UTF-8");
        if("Faild".equals(((Map<String, String>) ((Object) HttpRequest.parseXml(result).get(0))).get("returnstatus"))){
            return "1";
        }else if ("Success".equals(((Map<String, String>) ((Object) HttpRequest.parseXml(result).get(0))).get("returnstatus"))) {
                return "0";
        }else {
            return "1";
        }
    }

    /**
     * 获取验证码
     * @return
     */
    public static String getRandom() {
        String num = "";
        for (int i = 0 ; i < 6 ; i ++) {
            num = num + String.valueOf((int) Math.floor(Math.random() * 9 + 1));
        }
        return num;
    }
}
